# -*- coding: utf-8 -*-

from collections import OrderedDict

from django.core import paginator
from django.core.paginator import Paginator as DjangoPaginator
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from core.response import JsonResponse


class CustomPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = "limit"
    max_page_size = 1000
    django_paginator_class = DjangoPaginator

    def get_paginated_response(self, data):
        msg = '操作成功'
        page = int(self.get_page_number(self.request, paginator)) or 1
        limit = int(self.get_page_size(self.request)) or 10
        total = self.page.paginator.count
        return JsonResponse(paginate=True, data=data, msg=msg, page=page, limit=limit, total=total)
